package com.hot12345.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.hot12345.common.basedata.Constant;
import com.hot12345.vo.InfoVO;
import com.hot12345.common.freemarker.FreeMarkerManager;
import com.hot12345.common.util.ReadProperties;

public class IndexService {
	private final static Log log = LogFactory.getLog(IndexService.class);

	public static void index() throws Exception{
		
		Map<String,Object> modelMap = new HashMap<String,Object>();
		InfoServiceImpl infoSer = InfoServiceImpl.getInstance();
		
		
		List<InfoVO> lastTopAllList = infoSer.getInfoList(Constant.dateType_last,null, 0, 18);
		modelMap.put("lastTopAllList", lastTopAllList);
		
		List<InfoVO> weekTopAllList = infoSer.getInfoList(Constant.dateType_week,null, 0, 18);
		modelMap.put("weekTopAllList", weekTopAllList);
		
		List<InfoVO> monthTopAllList = infoSer.getInfoList(Constant.dateType_month,null, 0, 18);
		modelMap.put("monthTopAllList", monthTopAllList);
		
		List<InfoVO> newsList = infoSer.getInfoList(Constant.dateType_last,1, 0, 10);
		modelMap.put("newsList", newsList);
		
		List<InfoVO> newsWeekList = infoSer.getInfoList(Constant.dateType_week, 1, 0, 10);
		modelMap.put("newsWeekList", newsWeekList);
		
		List<InfoVO> newsMonthList = infoSer.getInfoList(Constant.dateType_month, 1, 0, 10);
		modelMap.put("newsMonthList", newsMonthList);
		
		List<InfoVO> yuleLastList = infoSer.getInfoList(Constant.dateType_last, 7, 0, 10);
		modelMap.put("yuleLastList", yuleLastList);
		
		List<InfoVO> yuleWeekList = infoSer.getInfoList(Constant.dateType_week, 7, 0, 10);
		modelMap.put("yuleWeekList", yuleWeekList);
		
		List<InfoVO> yuleMonthList = infoSer.getInfoList(Constant.dateType_month, 7, 0, 10);
		modelMap.put("yuleMonthList", yuleMonthList);
		
		//体育
		List<InfoVO> sportsLastList = infoSer.getInfoList(Constant.dateType_last, 6, 0, 10);
		modelMap.put("sportsLastList", sportsLastList);
		
		List<InfoVO> sportsWeekList = infoSer.getInfoList(Constant.dateType_week, 6, 0, 10);
		modelMap.put("sportsWeekList", sportsWeekList);
		
		List<InfoVO> sportsMonthList = infoSer.getInfoList(Constant.dateType_month, 6, 0, 10);
		modelMap.put("sportsMonthList", sportsMonthList);
		
		//热贴
		List<InfoVO> bbsLastList = infoSer.getInfoList(Constant.dateType_last, 2, 0, 18);
		modelMap.put("bbsLastList", bbsLastList);
		
		List<InfoVO> bbsWeekList = infoSer.getInfoList(Constant.dateType_week, 2, 0, 18);
		modelMap.put("bbsWeekList", bbsWeekList);
		
		List<InfoVO> bbsMonthList = infoSer.getInfoList(Constant.dateType_month, 2, 0, 18);
		modelMap.put("bbsMonthList", bbsMonthList);
		
		//点评
		List<InfoVO> dianpinLastList = infoSer.getInfoList(Constant.dateType_last, 8, 0, 5);
		modelMap.put("dianpinLastList", dianpinLastList);
		
		List<InfoVO> dianpinWeekList = infoSer.getInfoList(Constant.dateType_week, 8, 0, 5);
		modelMap.put("dianpinWeekList", dianpinWeekList);
		
		List<InfoVO> dianpinMonthList = infoSer.getInfoList(Constant.dateType_month, 8, 0, 5);
		modelMap.put("dianpinMonthList", dianpinMonthList);
		
		//电影
		List<InfoVO> videoLastList = infoSer.getInfoList(Constant.dateType_last, 11, 0, 10);
		modelMap.put("videoLastList", videoLastList);
		
		List<InfoVO> videoWeekList = infoSer.getInfoList(Constant.dateType_week, 11, 0, 10);
		modelMap.put("videoWeekList", videoWeekList);
		
		List<InfoVO> videoMonthList = infoSer.getInfoList(Constant.dateType_month, 11, 0, 10);
		modelMap.put("videoMonthList", videoMonthList);
		
		//军事
		List<InfoVO> junshiLastList = infoSer.getInfoList(Constant.dateType_last, 5, 0, 10);
		modelMap.put("junshiLastList", junshiLastList);
		
		List<InfoVO> junshiWeekList = infoSer.getInfoList(Constant.dateType_week, 5, 0, 10);
		modelMap.put("junshiWeekList", junshiWeekList);
		
		List<InfoVO> junshiMonthList = infoSer.getInfoList(Constant.dateType_month, 5, 0, 10);
		modelMap.put("junshiMonthList", junshiMonthList);
		
		//视频
		List<InfoVO> movieLastList = infoSer.getInfoList(Constant.dateType_last, 12, 0, 10);
		modelMap.put("movieLastList", movieLastList);
		
		List<InfoVO> movieWeekList = infoSer.getInfoList(Constant.dateType_week, 12, 0, 10);
		modelMap.put("movieWeekList", movieWeekList);
		
		List<InfoVO> movieMonthList = infoSer.getInfoList(Constant.dateType_month, 12, 0, 10);
		modelMap.put("movieMonthList", movieMonthList);
		
//		//游戏
//		List<InfoVO> gameLastList = infoSer.getInfoList(Constant.dateType_last, 3, 0, 10);
//		modelMap.put("gameLastList", gameLastList);
//		
//		List<InfoVO> gameWeekList = infoSer.getInfoList(Constant.dateType_week, 3, 0, 10);
//		modelMap.put("gameWeekList", gameWeekList);
//		
//		List<InfoVO> gameMonthList = infoSer.getInfoList(Constant.dateType_month, 3, 0, 10);
//		modelMap.put("gameMonthList", gameMonthList);
		
		//游戏资讯
		List<InfoVO> gamenewsLastList = infoSer.getInfoList(Constant.dateType_last, 15, 0, 10);
		modelMap.put("gamenewsLastList", gamenewsLastList);
		
		List<InfoVO> gamenewsWeekList = infoSer.getInfoList(Constant.dateType_week, 15, 0, 10);
		modelMap.put("gamenewsWeekList", gamenewsWeekList);
		
		List<InfoVO> gamenewsMonthList = infoSer.getInfoList(Constant.dateType_month, 15, 0, 10);
		modelMap.put("gamenewsMonthList", gamenewsMonthList);
		
		//连续剧
		List<InfoVO> tvLastList = infoSer.getInfoList(Constant.dateType_last, 13, 0, 10);
		modelMap.put("tvLastList", tvLastList);
		
		List<InfoVO> tvWeekList = infoSer.getInfoList(Constant.dateType_week, 13, 0, 10);
		modelMap.put("tvWeekList", tvWeekList);
		
		List<InfoVO> tvMonthList = infoSer.getInfoList(Constant.dateType_month, 13, 0, 10);
		modelMap.put("tvMonthList", tvMonthList);
		
		//小说
//		List<InfoVO> xiaoshuoLastList = infoSer.getInfoList(Constant.dateType_last, 9, 0, 10);
//		modelMap.put("xiaoshuoLastList", xiaoshuoLastList);
//		
//		List<InfoVO> xiaoshuoWeekList = infoSer.getInfoList(Constant.dateType_week, 9, 0, 10);
//		modelMap.put("xiaoshuoWeekList", xiaoshuoWeekList);
//		
//		List<InfoVO> xiaoshuoMonthList = infoSer.getInfoList(Constant.dateType_month, 9, 0, 10);
//		modelMap.put("xiaoshuoMonthList", xiaoshuoMonthList);
		
		List<InfoVO> societyLastList = infoSer.getInfoList(Constant.dateType_last, 14, 0, 10);
		modelMap.put("societyLastList", societyLastList);
		
		List<InfoVO> societyWeekList = infoSer.getInfoList(Constant.dateType_week, 14, 0, 10);
		modelMap.put("societyWeekList", societyWeekList);
		
		List<InfoVO> societyMonthList = infoSer.getInfoList(Constant.dateType_month, 14, 0, 10);
		modelMap.put("societyMonthList", societyMonthList);
		
		//情感
		List<InfoVO> ganqingLastList = infoSer.getInfoList(Constant.dateType_last, 4, 0, 10);
		modelMap.put("ganqingLastList", ganqingLastList);
		
		List<InfoVO> ganqingWeekList = infoSer.getInfoList(Constant.dateType_week, 4, 0, 10);
		modelMap.put("ganqingWeekList", ganqingWeekList);
		
		List<InfoVO> ganqingMonthList = infoSer.getInfoList(Constant.dateType_month, 4, 0, 10);
		modelMap.put("ganqingMonthList", ganqingMonthList);
		
		//情感
		List<InfoVO> kaixinLastList = infoSer.getInfoList(Constant.dateType_last, 16, 0, 10);
		modelMap.put("kaixinLastList", kaixinLastList);
		
		List<InfoVO> kaixinWeekList = infoSer.getInfoList(Constant.dateType_week, 16, 0, 10);
		modelMap.put("kaixinWeekList", kaixinWeekList);
		
		List<InfoVO> kaixinMonthList = infoSer.getInfoList(Constant.dateType_month, 16, 0, 10);
		modelMap.put("kaixinMonthList", kaixinMonthList);
		
		modelMap.put("isIndex", true);
		
///////////////////-----------------开始创建html-------------------/////////////////////////
		FreeMarkerManager fmm = FreeMarkerManager.getInstance();
		
		/**
		 * 读取属性文件获取ftl模板路径和html路径
		 */
		//属性文件路径
//		logger.error("index.getResource========="+HtmlService.class.getResource(""));
//		logger.error("index.getPath========="+HtmlService.class.getResource("").getPath());
		String getPath = null;
		try {
			getPath = IndexService.class.getResource("").getPath();
		} catch (Exception e) {
			log.error("读取ftl模板路径为空",e);
			throw new Exception(e);
		}
		try {
			getPath = getPath.substring(0, getPath.indexOf("WEB-INF/classes"));
		} catch (Exception e) {
			log.error("查询ftl模板路径为空！",e);
			throw new Exception(e);
		}
//		logger.error("index.getPath============"+getPath);
        //html路径
        String htmlPath = null;
        htmlPath = ReadProperties.readValueBySystem("htmlPath");
//        logger.error("index.htmlPath============"+htmlPath);
        //ftl模板路径
        String templatePath =  getPath +"/"+ ReadProperties.readValueBySystem("templatePath");
//        logger.error("index.templatePath============"+templatePath);
        fmm.createHtmlFile(templatePath,"home/index.ftl", modelMap, htmlPath, "index.html");
	}
}
